package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.io.Serializable;
import java.time.LocalDate;

/**
 * 维保信息维护
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_it_net_assets_maintenance_information set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@SQLDeleteAll(sql = "update t_gw_it_net_assets_maintenance_information set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
//不需要唯一索引
@Table(name = "t_gw_it_net_assets_maintenance_information", indexes = {@Index(name = "IDX_SERIAL_NUM", columnList = "serial_num")})
public class MaintenanceInformation extends BaseEntity implements Serializable {

    private static final long serialVersionUID = -2357098316870993284L;

    @Column(name = "serial_num", columnDefinition = "varchar(128) not null comment '网络资产序列号'")
    private String serialNum;

    @Column(name = "maintenance_info", columnDefinition = "varchar(128) not null comment '维保信息'")
    private String maintenanceInfo;

    @Column(name = "supplier", columnDefinition = "varchar(128) comment '供应商'")
    private String supplier;

    @Column(name = "start", columnDefinition = "date comment '开始日期'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate start;

    @Column(name = "end", columnDefinition = "date comment '结束日期'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate end;

    @Column(name = "bind_oa", columnDefinition = "varchar(128) comment '关联OA'")
    private String bindOa;

}
